package com.spic.business.accident.exterevents.selfInspectionReport.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import com.spic.business.accident.exterevents.selfInspectionReport.domain.AccidentExternalEventInspectionReport;
import com.spic.business.accident.exterevents.selfInspectionReport.service.IAccidentExternalEventInspectionReportService;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.page.TableDataInfo;

/**
 * 外部事件自查报告Controller
 * 
 * @author spic
 * @date 2021-12-03
 */
@RestController
@RequestMapping("/accident/exterevents/exterEventClassReport")
public class AccidentExternalEventInspectionReportController extends BaseController
{
    @Autowired
    private IAccidentExternalEventInspectionReportService accidentExternalEventInspectionReportService;

    /**
     * 查询外部事件自查报告列表
     */
    @PreAuthorize(hasPermi = "business/accident/exterevents:exterEventClassReport:list")
    @GetMapping("/list")
    public TableDataInfo list(AccidentExternalEventInspectionReport accidentExternalEventInspectionReport)
    {
        startPage();
        List<AccidentExternalEventInspectionReport> list = accidentExternalEventInspectionReportService.selectAccidentExternalEventInspectionReportList(accidentExternalEventInspectionReport);
        return getDataTable(list);
    }

    /**
     * 导出外部事件自查报告列表
     */
    @PreAuthorize(hasPermi = "business/accident/exterevents:exterEventClassReport:export")
    @Log(title = "外部事件自查报告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AccidentExternalEventInspectionReport accidentExternalEventInspectionReport) throws IOException
    {
        List<AccidentExternalEventInspectionReport> list = accidentExternalEventInspectionReportService.selectAccidentExternalEventInspectionReportList(accidentExternalEventInspectionReport);
        ExcelUtil<AccidentExternalEventInspectionReport> util = new ExcelUtil<AccidentExternalEventInspectionReport>(AccidentExternalEventInspectionReport.class);
        util.exportExcel(response, list, "外部事件自查报告数据");
    }

    /**
     * 获取外部事件自查报告详细信息
     */
    @PreAuthorize(hasPermi = "business/accident/exterevents:exterEventClassReport:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(accidentExternalEventInspectionReportService.selectAccidentExternalEventInspectionReportById(id));
    }

    /**
     * 新增外部事件自查报告
     */
    @PreAuthorize(hasPermi = "business/accident/exterevents:exterEventClassReport:add")
    @Log(title = "外部事件自查报告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AccidentExternalEventInspectionReport accidentExternalEventInspectionReport)
    {
        return toAjax(accidentExternalEventInspectionReportService.insertAccidentExternalEventInspectionReport(accidentExternalEventInspectionReport));
    }

    /**
     * 修改外部事件自查报告
     */
    @PreAuthorize(hasPermi = "business/accident/exterevents:exterEventClassReport:edit")
    @Log(title = "外部事件自查报告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AccidentExternalEventInspectionReport accidentExternalEventInspectionReport)
    {
        return toAjax(accidentExternalEventInspectionReportService.updateAccidentExternalEventInspectionReport(accidentExternalEventInspectionReport));
    }

    /**
     * 删除外部事件自查报告
     */
    @PreAuthorize(hasPermi = "business/accident/exterevents:exterEventClassReport:remove")
    @Log(title = "外部事件自查报告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(accidentExternalEventInspectionReportService.deleteAccidentExternalEventInspectionReportByIds(ids));
    }
}
